import {NumberUtil} from "../utils/NumberUtil";

export class FrameSpeedHolder {
  private logicUpdateCount = 0;
  private renderUpdateCount = 0;

  private lastLogicFrameTime: number = 0
  private lastRenderLogicTime: number = 0

  private logicFramePerSecond: number = 0
  private renderFramePerSecond: number = 0

  getLogicFramesPerSecond(): number {

    return this.logicFramePerSecond
  }

  getRenderFramesPerSecond(): number {

    return this.renderFramePerSecond
  }

  onLogicFrameUpdate() {
    this.logicUpdateCount++;
    if(this.logicUpdateCount%10==0){
      const now = Date.now()
      const passed = now - this.lastLogicFrameTime
      this.lastLogicFrameTime = now

      this.logicFramePerSecond = Math.round(10000/ passed)
    }

  }

  onRenderFrameUpdate() {
    this.renderUpdateCount++
    if(this.renderUpdateCount%10==0){
      const now = Date.now()
      const passed = now - this.lastRenderLogicTime
      this.lastRenderLogicTime = now
      this.renderFramePerSecond = Math.round(10000 / passed)
    }

  }
}
